﻿using DearlerPlatfrom.Core;
using DearlerPlatfrom.Service.Common;
using DearlerPlatfrom.Service.ProductApp;
using DearlerPlatfrom.Service.ProductApp.Dto;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DearlerPlatfrom.Web.Controllers
{
    /// <summary>
    /// 产品服务
    /// </summary>
   // [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class ProductController : BaseController
    {
        private readonly IProductService _productService;

        public ProductController(IProductService productService)
        {
            _productService = productService;
        }

        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <param name="orderBy">排序</param>
        /// <param name="pageIndex">页</param>
        /// <param name="pageSize">数量</param>
        /// <param name="blongType">数量</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IEnumerable<ProductDto>> GetProductDto(string blongType, string orderBy, int pageIndex = 1, int pageSize = 10, OrderType order = OrderType.Asc)
        {
            //pageIndex = pageIndex | 1;//短路运算符
            //pageSize = pageSize | 10;
            return await _productService.GetProductDto(blongType.ToLower(), new PageWithSortDto
            {
                order = order,
                PageIndex = pageIndex,
                PageSize = pageSize,
                Sort = orderBy
            });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet("Type")]
        public async Task<IEnumerable<ProductTypeDto>> GetProductType()
        {
            return await _productService.GetProductType();
        }


        [HttpGet("Types")]

        public async Task<Dictionary<string, IEnumerable<string>>> ListProductTypes(string belongTypeName, string typeNo)
        {
            return await _productService.ListProductTypes(belongTypeName, typeNo);
        }

    }
}
